Support 16bit pnms
authorMatthias Clasen <matthiasc@src.gnome.org>
Fri, 3 Mar 2006 17:19:27 +0000 (17:19 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Fri, 3 Mar 2006 17:19:27 +0000 (17:19 +0000)
gdk-pixbuf/ChangeLog
gdk-pixbuf/io-pnm.c

index 3e8dc05d39d354c0b87113b69f906df8f05b9810..0a52458092c4c1292d963c74b2d116eae78c37e1 100644 (file)
@@ -1,3 +1,8 @@
+2006-03-03  Matthias Clasen  <mclasen@redhat.com>
+
+       * io-pnm.c: Support pnm files with maxval > 255.
+       (#327560, Matthijs Douze)
+
 2006-03-03  Matthias Clasen  <mclasen@redhat.com>
 
        * io-pcx.c (pcx_load_palette_8): Fix incremental loading
index 81225740ad46fb6c5d4df8ea1f073e8abae96aad..3af9794c252d994b81ef3682998f839b4a4fb064 100644 (file)
@@ -392,13 +392,6 @@ pnm_read_header (PnmLoaderContext *context)
                                return PNM_FATAL_ERR;
                        }
 
-                       if (context->maxval > 255) {
-                               g_set_error (context->error,
-                                            GDK_PIXBUF_ERROR,
-                                            GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
-                                            _("Cannot handle PNM files with maximum color values greater than 255"));
-                               return PNM_FATAL_ERR;
-                       }
                }
                break;
        default:
@@ -438,6 +431,8 @@ pnm_read_raw_scanline (PnmLoaderContext *context)
                             _("Raw PNM image type is invalid"));
                return PNM_FATAL_ERR;
        }
+       if(context->maxval>255) 
+               numpix/=2;
        
        numpix = MIN (numpix, context->width - context->output_col);
        
@@ -466,6 +461,8 @@ pnm_read_raw_scanline (PnmLoaderContext *context)
                             _("Raw PNM image type is invalid"));
                return PNM_FATAL_ERR;
        }
+       if(context->maxval>255) 
+               numbytes*=2;                            
        
        switch (context->type) {
        case PNM_FORMAT_PBM_RAW:
@@ -479,6 +476,17 @@ pnm_read_raw_scanline (PnmLoaderContext *context)
                if (context->maxval == 255) {
                        /* special-case optimization */
                        memcpy (dest, inbuf->byte, numbytes);
+               } else if(context->maxval == 65535) {
+                       /* optimized version of the next case */
+                       for(i=0; i < numbytes ; i+=2) {
+                               *dest++=inbuf->byte[i];
+                       }
+               } else if(context->maxval > 255) {
+                       /* scale down to 256 colors */
+                       for(i=0; i < numbytes ; i+=2) {
+                               guint v=inbuf->byte[i]*256+inbuf->byte[i+1];
+                               *dest++=v*255/context->maxval;
+                       }
                } else {
                        for (i = 0; i < numbytes; i++) {
                                guchar *byte = inbuf->byte + i;
@@ -591,7 +599,7 @@ pnm_read_ascii_scanline (PnmLoaderContext *context)
                                break;
                        case PNM_FORMAT_PGM:
                        case PNM_FORMAT_PPM:
-                               /* scale the color to an 8-bit color depth */
+                               /* scale the color up or down to an 8-bit color depth */
                                if (value > context->maxval)
                                        *dptr++ = 255;
                                else